<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="keywords" content="" />
<meta name="descrption" content="" />
<title>贷款利率计算器</title>
<script src="../../../js/angular.js" charset="utf-8"></script>
<link rel="stylesheet" href="../../../layui/css/layui.css" media="all" />
<script src="../../../layui/layui.js" charset="utf-8"></script>
<script src="../../../layui/jquery-3.2.1.min.js" charset="utf-8"></script>
</head>
<body>
	<div id="page_container" style="width: 100%">
		<!--左部  -->
		<fieldset class="layui-elem-field layui-field-title"
			style="margin-top: 30px;">
			<legend>贷款利率计算器</legend>
		</fieldset>
		<div ng-app="myApp" ng-controller="customersCtrl" align="center">
			<div style="float:left;width:35%">
				<div class="layui-form-item">
					<label class="layui-form-label" style="width: 130px;text-align: left;">贷款金额（元）:</label>
					<div class="layui-input-block">
						<input ng-model="dkje" lay-verify="title" autocomplete="off"
							class="layui-input" type="text" style="width: 80%">
					</div>
				</div>
				<div class="layui-form-item">
					<label class="layui-form-label" style="width: 130px;text-align: left;">贷款期限（年）:</label>
					<div class="layui-input-block">
						<input ng-model="dkqx" lay-verify="title" autocomplete="off"
							class="layui-input" type="text" style="width: 80%">
					</div>
				</div>
				<div class="layui-form-item">
					<label class="layui-form-label" style="width: 130px;text-align: left;">还款方式:</label>
					<div class="layui-input-block">
						<select ng-model="selectedfs" ng-model="hkfsmd"
							ng-change="hkfsfun()" style="width:80%;height:35px;">
							<option ng-repeat="x in hkfs" value="{{x.hk}}">{{x.fs}}</option>
						</select>
					</div>
				</div>
				<div class="layui-form-item">
					<div class="layui-input-block">
						<button class="layui-btn" ng-click="js()">计算</button>
						<button type="reset" ng-click="cz()"
							class="layui-btn layui-btn-primary">重置</button>
					</div>
				</div>
				<div class="layui-form-item">
					<label class="layui-form-label" style="width: 130px;text-align: left;">还款总额:</label>
					<div class="layui-input-block">
						<input name="title" lay-verify="title" ng-model="HKZE" autocomplete="off"
							class="layui-input" type="text" style="width: 80%">
					</div>
				</div>
				<div class="layui-form-item">
					<label class="layui-form-label" style="width: 130px;text-align: left;">利息总额:</label>
					<div class="layui-input-block">
						<input name="title" lay-verify="title" ng-model="LXZE" autocomplete="off"
							class="layui-input" type="text" style="width: 80%">
					</div>
				</div>
			</div>
			<!--右部  -->
			<div style="float:right;width:60%">
				<table class="layui-table">
					<tr align="center" style="background-color:#f1f1f1">
						<td>期次</td>
						<td>偿还本息</td>
						<td>偿还本金</td>
						<td>偿还利息</td>
					</tr>
					<tr align="center" ng-repeat="x in names">
						<td ng-if="$odd" style="background-color:#f1f1f1">{{ x.QC}}</td>
						<td ng-if="$even">{{ x.QC }}</td>
						<td ng-if="$odd" style="background-color:#f1f1f1">{{ x.CHBX}}</td>
						<td ng-if="$even">{{ x.CHBX}}</td>
						<td ng-if="$odd" style="background-color:#f1f1f1">{{ x.CHBJ}}</td>
						<td ng-if="$even">{{ x.CHBJ }}</td>
						<td ng-if="$odd" style="background-color:#f1f1f1">{{ x.CHLX}}</td>
						<td ng-if="$even">{{ x.CHLX }}</td>
					</tr>
				</table>
				<div class="layui-btn-group">
					<button class="layui-btn layui-btn-primary layui-btn-sm"
						ng-click="Sy()">首页</button>
					<button class="layui-btn layui-btn-primary layui-btn-sm"
						ng-click="Previous()">上一页</button>
					<button ng-repeat="page in pageList"
						class="layui-btn layui-btn-primary layui-btn-sm"
						ng-click="selectPage(page)">{{ page }}</button>
					<button class="layui-btn layui-btn-primary layui-btn-sm"
						ng-click="Next()">下一页</button>
					<button class="layui-btn layui-btn-primary layui-btn-sm"
						ng-click="Wy()">尾页</button>
					<button class="layui-btn layui-btn-primary layui-btn-sm ">{{selPage}}/{{pages}}</button>
				</div>
			</div>
		</div>
	</div>


	<script>
	  function getPath(){
			 return 'http://'+location.host;	
		      };
	   var app = angular.module('myApp', []);
		 app.controller('customersCtrl', function($scope, $http) {
                  $scope.hkfs = [
                 {fs : "等额本息", hk : "等额本息"},
                 {fs : "等额本金", hk : "等额本金"},
                  ];
                  $scope.hkfsfun=function(){
                     var selectval=$scope.selectedfs;
                     $scope.hkfsmd=selectval;
                  };
                  $scope.js=function(){
                  $scope.params = {
                     hkfs : $scope.hkfsmd,
                     year: $scope.dkqx,
                     invest:$scope.dkje
                     				  };
			     $http({
					url : getPath() + "/wsyyt/DKJSQController/test",
					contentType : "text/html;charset=utf-8",
					method : 'post',
					params : $scope.params,
				}).then(function(res){
				
				     $scope.data = res.data;
				     /**计算还款总额，利息总额  */
				     var HK=0.00;
				     for(var i=0;i<res.data.length;i++){
				        HK=res.data[i].CHBX*1 +HK*1;
				        
				     }
				     var numhk=HK.toFixed(3);
				     var endhk=numhk.substring(0,numhk.lastIndexOf('.')+3);
				     $scope.HKZE=endhk;
				      
				     var LX=0.00;
				     for(var i=0;i<res.data.length;i++){
				        LX=LX*1+res.data[i].CHLX*1;
				     }
				     var numlx=LX.toFixed(3);
				     var endlx=numlx.substring(0,numlx.lastIndexOf('.')+3);
				     $scope.LXZE=endlx;
				     
				    $scope.pageSize = 12;//设置显示行数
      $scope.pages = Math.ceil($scope.data.length / $scope.pageSize); //分页数
      $scope.newPages = $scope.pages > 5 ? 5 : $scope.pages;
      $scope.pageList = [];
      $scope.selPage = 1;
      //设置表格数据源(分页)
      $scope.setData= function () {
        $scope.names = $scope.data.slice(($scope.pageSize * ($scope.selPage - 1)), ($scope.selPage * $scope.pageSize));//通过当前页数筛选出表格当前显示数据
      },
      $scope.names = $scope.data.slice(0, $scope.pageSize);
      //分页要repeat的数组
      for (var i = 0; i < $scope.newPages; i++) {
        $scope.pageList.push(i + 1);
      }
      //打印当前选中页索引
      $scope.selectPage = function (page) {
        //不能小于1大于最大
        if (page < 1 || page > $scope.pages) return;
        //最多显示分页数5
        if (page > 2) {
          //因为只显示5个页数，大于2页开始分页转换
          var newpageList = [];
          for (var i = (page - 3) ; i < ((page + 2) > $scope.pages ? $scope.pages : (page + 2)) ; i++) {
            newpageList.push(i + 1);
          }
          $scope.pageList = newpageList;
        }else if (page ==1||page==2) {
          var newpageList = [];
          for (var i = 1 ; i < 3; i++) {
            newpageList.push(i);
          }
          $scope.pageList = newpageList;
        }
        $scope.selPage = page;
        $scope.setData();
        $scope.isActivePage(page);
        console.log("选择的页：" + page);
      };
      //设置当前选中页样式
      $scope.isActivePage = function (page) {
        return $scope.selPage == page;
      };
      //上一页
      $scope.Previous = function () {
        $scope.selectPage($scope.selPage - 1);
      }
      //下一页
      $scope.Next = function () {
        $scope.selectPage($scope.selPage + 1);
      }; 
      $scope.Sy = function () {
        $scope.selectPage(1);
      };
         $scope.Wy = function () {
        $scope.selectPage( $scope.pages);
     					 };	
			  });
		};
		});
	</script>
</body>
</html>
